package fr.sharpe.app.earthvisualizationproject.controller.servers;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;

import com.mycila.event.api.Dispatcher;
import com.mycila.event.api.topic.Topics;

import fr.sharpe.app.earthvisualizationproject.event.AddIconsEvent;
import fr.sharpe.app.earthvisualizationproject.event.AddMarkerPointsEvent;
import fr.sharpe.app.earthvisualizationproject.event.AddSurfacesEvent;
import fr.sharpe.app.earthvisualizationproject.event.AddTextsEvent;
import fr.sharpe.app.earthvisualizationproject.event.DeleteLayerEvent;

import fr.sharpe.app.earthvisualizationdatamodel.MarkerPoint;
import fr.sharpe.app.earthvisualizationdatamodel.Surface;
import fr.sharpe.app.earthvisualizationdatamodel.Text;
import fr.sharpe.app.earthvisualizationdatamodel.services.RmiServices;

public class RmiServicesImpl extends UnicastRemoteObject implements RmiServices{

	private Dispatcher dispatcher;
	
	public RmiServicesImpl(Dispatcher dispatcher) throws RemoteException {
		super();
		this.dispatcher = dispatcher;
	}

	public void addMarkers(String layerName, ArrayList<MarkerPoint> markers) throws RemoteException {
		dispatcher.publish(Topics.topic("AddMarkerPoints"), new AddMarkerPointsEvent(markers,layerName));
	}

	public void addSurfaces(String layerName, ArrayList<Surface> surfaces) throws RemoteException {
		dispatcher.publish(Topics.topic("AddSurfaces"), new AddSurfacesEvent(surfaces, layerName));
	}

	public void addTexts(String layerName, ArrayList<Text> texts) throws RemoteException {
		dispatcher.publish(Topics.topic("AddTexts"), new AddTextsEvent(texts, layerName));
	}

	public void addIcons(String layerName, ArrayList<Surface> icons)throws RemoteException {
		dispatcher.publish(Topics.topic("AddIcons"), new AddIconsEvent(icons, layerName));
	}

	public void deleteLayer(String layerName) throws RemoteException {
		dispatcher.publish(Topics.topic("DeleteLayer"), new DeleteLayerEvent(layerName));	
	}
}
